//
//  TxtReadVc.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/11.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "TxtReadVc.h"
#import "BdTV.h"
#import "config.h"
#import "NSString+StringHight.h"
#import "StringTool.h"



@interface TxtReadVc ()

-(void)initView;
-(void)btnOnclick:(UIButton*)sender;

@end

@implementation TxtReadVc
@synthesize titleStr,subCategoryTitleStr,txtStr;

- (void)viewDidLoad {
    [super viewDidLoad];

    
    [self initView];
}



-(void)initView{
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    BdTV *title = [[BdTV alloc]initWithFrame:CGRectMake(0, 0, PMW, 44)];
    [title.backBtn setTag:11];
    [title.backBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    [[title doneBtn] removeFromSuperview];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:title];
    [title setMianTitle:self.titleStr];
    
    
    int beginY = 0;
    if (![StringTool isBlankString:self.subCategoryTitleStr]) {
        UILabel *subLab = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, PMW-20, 0)];
        [subLab setFont:[UIFont systemFontOfSize:15]];
        [subLab setLineBreakMode:NSLineBreakByCharWrapping];
        [subLab setNumberOfLines:0];
        [subLab setTextColor:UIColorFromRGB(0x333333)];
        subLab.attributedText = [self.subCategoryTitleStr attributedStringFromStingWithFont:subLab.font withLineSpacing:3];
        [subLab sizeToFit];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, GET_VIEW_BOTTOM_POS(subLab)+12, PMW, 2)];
        [line setBackgroundColor:UIColorFromRGB(0xe3e3e3)];
        [self.view addSubview:line];
        [self.view addSubview:subLab];
        
        beginY = GET_VIEW_BOTTOM_POS(line);
    }
    
    
    
    UIScrollView *svc = [[UIScrollView alloc]initWithFrame:CGRectMake(0, beginY, PMW, PMH-beginY-NAV_HIGHT)];
    [self.view addSubview:svc];
    UILabel *txtLab = [[UILabel alloc]initWithFrame:CGRectMake(15, 20, svc.frame.size.width-30, svc.frame.size.height-20)];
    [txtLab setFont:[UIFont systemFontOfSize:16]];
    [txtLab setTextColor:UIColorFromRGB(0x333333)];
    [txtLab setLineBreakMode: NSLineBreakByCharWrapping];
    [txtLab setNumberOfLines:0];
    [svc addSubview:txtLab];

    
    if ([StringTool isBlankString:self.attStr.string]==false) {
         txtLab.attributedText = self.attStr;
    }else{
         txtLab.attributedText = [txtStr attributedStringFromStingWithFont:txtLab.font withLineSpacing:7];
    }
    
    [txtLab sizeToFit];

    
    int congH = txtLab.frame.size.height+40;
    
    [svc setContentSize:CGSizeMake(PMW, MAX(congH, svc.frame.size.height+1))];
    
}




-(void)btnOnclick:(UIButton *)sender{
    
    switch (sender.tag) {
            
        case 11:
            
            [self.navigationController popViewControllerAnimated:YES];
            break;
            
        case 22:
            
            break;

            
    }
}

@end
